package com.example.common;

import lombok.Data;

import java.util.HashMap;
import java.util.Map;

@Data
public class R {
    private Boolean success = true;
    private Integer code;
    private String message;
    private Map<String, Object> data = new HashMap<>();

    public static R ok() {
        R r = new R();
        r.setSuccess(true);
        r.setCode(ResultCode.SUCCESS);
        r.setMessage("成功");
        return r;
    }

    public static R error() {
        R r = new R();
        r.setSuccess(true);
        r.setCode(ResultCode.ERROR);
        r.setMessage("成功");
        return r;
    }

    public R Success(Boolean success) {
        setSuccess(success);
        return this;
    }



    public R Code(Integer code) {
       setCode(code);
       return this;
    }



    public R Message(String message) {
        setMessage(message);
        return this;
    }


    public R Data(Map<String, Object> data)
    {
       setData(data);
       return this;
    }

    public R Data(String token, String jwt) {
        data.putIfAbsent(token, jwt);
        return this;
    }
}

